//package edu.zut.cn.service;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import edu.zut.cn.domain.entity.LoginUser;
//import edu.zut.cn.domain.entity.User;
//import edu.zut.cn.mapper.UserMapper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import java.util.Objects;
//
///**
// *  UserDetailService 用于Security登录流程时查询数据库操作
// *
// * @author 张小訫
// */
//@Service
//public class UserDetailsServiceImpl implements UserDetailsService {
//    @Autowired
//    private UserMapper userMapper;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(User::getUserName, username);
//        User user = userMapper.selectOne(queryWrapper);
//        //判断是否查到用户  如果没查到抛出异常
//        if (Objects.isNull(user)) {
//            throw new RuntimeException("用户不存在");
//        }
//        //返回用户信息
//        return new LoginUser(user);
//    }
//}